<?php
	function toTwitter($PeId, $title, $message){
                //generates the shorten message for Twitter

                @ $db = mysqli_connect("localhost","root","gibbiX12345","msghub");
                $checkname = "SELECT Name, Firstname FROM Person WHERE PeId = '".$PeId."'";
                $execname = $db->query($checkname);
                $fetchname = $execname->fetch_assoc();
                $namestr = $fetchname['Firstname']." ".$fetchname['Name'];

                $namelen = strlen($namestr);    //how long is the name
                $stringlen = strlen(" Would like to contact you on the subject of '', please check your email!");
		$textlen = strlen($message);
                $maxlen = 140 -$namelen -$stringlen -7;

		if ($textlen +7 +$namelen <= 140){
			$shortmessage = $namestr." says: ".$message;
		} else {
			if (strlen($title) <= $maxlen){
				$twittitle = $title;
			} else {
				$twittitle = substr($title, 0, $maxlen)."[...]";
			}
			$shortmessage = $namestr." would like to contact you on the subject of '".$twittitle."', please check your email!";
		}

                //$shortmessage = $namestr." would like to contact you on the subject of '".$twittitle."', please check your email!";
                return($shortmessage);
	}
?>
